angular.
module('adminLogin').
component('adminLogin', {
  templateUrl:
  'views/app/admin-login/admin_login.template.html',
  controller: function ($scope,$cookies,$http,$window,$location,$rootScope) {
    console.log('asdsadsadxx')
    $scope.alert = false
    $rootScope.title = "管理员登录"
    $scope.userid = $cookies.get('userid')
    $scope.error = false
    console.log($scope.userid,'sds')
    if ($scope.userid != undefined){
      // navigate to data page
      $location.path('/')
    }

    $scope.login = function(){  
      console.log($scope.account,$scope.password)
      var dataobj = {'account' : $scope.account,'password' : $scope.password}
      $http.post('/admin/admin_login',dataobj).then(function(response){
        if (response.data.code == 200){
          console.log(response.data.session)
          createCookie('user',$scope.account,0.6)
          createCookie('sessionID' , response.data.session, 0.6)
          createCookie('right',0,0.6)
          $rootScope.rights = response.data.rights
          // gegenerate session id?
          $location.path('/')
        }
        else{
          angular.element('#alert').css({'display':'block'})
          $scope.alert = true
        }
      })
    } 





  }})



